#!/usr/bin/php -q
<?php
	if ($argc == 3 && is_numeric($argv[2]))
	{
		# grab command line arguments
		$url = $argv[1];
		$width = $argv[2];

		# get info about original media
		$media = @imagecreatefromjpeg($url);
		$old_x=imageSX($media);
		$old_y=imageSY($media);

		# maintain aspect ratio
		$thumb_w = $width;
		$thumb_h = $old_y * ($width / $old_x);
		
		# create thumbnail of media
		$thumb = ImageCreateTrueColor($thumb_w,$thumb_h);
		imagecopyresampled($thumb, $media, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); 

		# output image binary and free memory
		imagejpeg($thumb);
		imagedestroy($thumb);
	}

	return true;
?>
